//
//  LLT_SearchViewController.m
//  CoderLLT
//
//  Created by 刘晓萌 on 15/12/31.
//  Copyright © 2015年 刘晓萌. All rights reserved.
//

#import "LLT_SearchViewController.h"
#import "UIViewController+LLT_LoginAndRegist_LXM.h"
#import "UIViewController+LLT_UIViewControllerTools.h"

@interface LLT_SearchViewController ()<UIWebViewDelegate,UISearchBarDelegate>

@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
@property (weak, nonatomic) IBOutlet UIWebView *showWeb;
@property (copy , nonatomic) NSString *url;
@end

@implementation LLT_SearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeView];
    [self setDelegate];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

#pragma mark -- 设置页面

-(void)makeView{
    
}

-(void)setDelegate{
    self.showWeb.delegate = self;
    self.searchBar.delegate = self;
}

-(void)setWebView:(NSString *)url{
    [self.showWeb loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}


#pragma mark -- 点击事件
- (IBAction)didClickLeftBack:(UIButton *)sender {
    DissMissBack;
}
#pragma mark --- searchBar 协议

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar{
    if (searchBar.text.length > 0) {
        
        NSString *urlString= [NSString stringWithFormat:@"http://lolmax.com/search/?q=%@",searchBar.text];
                              
        self.url  = [NSString stringWithCString:[urlString UTF8String] encoding:NSUnicodeStringEncoding];
        
        [self setWebView:self.url];
        return YES;
    }else{
        return NO;
    }
}

#pragma mark --- uiwebView 协议
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
//{
//    NSString *str = [request URL].absoluteString;
//    str = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//    
//    NSString *strsub = [str substringToIndex:6];
//    NSString *s = @"maxjia://PageConfigJson#/";
//    if ([strsub isEqualToString:@"maxjia"]) {
//        str =  [str stringByReplacingOccurrencesOfString:s withString:@""];
//        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData: [str dataUsingEncoding:NSUTF8StringEncoding]
//                                                            options: NSJSONReadingMutableContainers
//                                                              error: nil];
//        
//        LLT_DetailOfArticleModel *urls = [[LLT_DetailOfArticleModel alloc]init];
//        [urls setValuesForKeysWithDictionary:dic[@"result"]];
//        LLT_ItemInfoViewController_LXM *infoVC = [MainStoryBoard instantiateViewControllerWithIdentifier:@"itemInfoVC"];
//        infoVC.itemUrls = urls;
//        [self presentViewController:infoVC animated:YES completion:nil];
//    }
    return YES;
}

@end
